﻿<script>
    new Promise((resolve, reject) => {
        console.log('one');
        return resolve({ result: true, data: [{ name: 'tom', age: 18 }] });
    })
        .then(result => {
            console.log('two');
            return new Promise((resolve, reject) => { resolve(result.data); })
        })
        .then(result => {
            console.log('three');
            return new Promise((resolve, reject) => { resolve(result[0]); })
        })
        .then(result => {
            console.log('four');
            console.log(result.name);
        });


    const p1 = new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve('结果1')
        }, 1000);
    })
    const p2 = new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve('结果2')
        }, 1000);
    })
    const p3 = new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve('结果3')
        }, 1000);
    })
    // 三个都成功则成功，只要有一个失败就失败
    // 成功时则会返回一个数组
    Promise.all([p1, p2, p3]).then(res => {
        console.log(res);
    })
</script>